API: Add gtk_widget_path_to_string()
authorBenjamin Otte <otte@redhat.com>
Sat, 26 Mar 2011 13:29:32 +0000 (14:29 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 27 Mar 2011 00:47:17 +0000 (01:47 +0100)
Dumps the widget path into a string representation. It tries to match the CSS
style as closely as possible (Note that there might be paths that cannot be
represented in CSS).

The main use of this code is for debugging purposes, so that you can
g_print() the path or dump it in a gdb session.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkwidgetpath.c
gtk/gtkwidgetpath.h

index 024645afd333db693f1d2286295252c41a5c63d9..5bdeea25172993edb447232832527d3958bfb6f6 100644 (file)
@@ -5438,6 +5438,7 @@ gtk_widget_path_iter_set_object_type
 gtk_widget_path_length
 gtk_widget_path_new
 gtk_widget_path_prepend_type
+gtk_widget_path_to_string
 
 <SUBSECTION Standard>
 GTK_TYPE_WIDGET_PATH
index 39485e06872cecadeefb5679f33ddde5a16d4110..6352c4c1ec1ff083d6b59fb82c2941f5600e01ab 100644 (file)
@@ -3588,6 +3588,7 @@ gtk_widget_path_iter_set_object_type
 gtk_widget_path_length
 gtk_widget_path_new
 gtk_widget_path_prepend_type
+gtk_widget_path_to_string
 gtk_widget_pop_composite_child
 gtk_widget_push_composite_child
 gtk_widget_queue_compute_expand
index 177f7b866d9e0508dbc366258e86295514594bc9..b59229a3abf37060238db0382337aec91f8d14b8 100644 (file)
@@ -224,6 +224,90 @@ gtk_widget_path_length (const GtkWidgetPath *path)
   return path->elems->len;
 }
 
+/**
+ * gtk_widget_path_to_string:
+ * @path: the path
+ *
+ * Dumps the widget path into a string representation. It tries to match
+ * the CSS style as closely as possible (Note that there might be paths
+ * that cannot be represented in CSS).
+ *                 
+ * The main use of this code is for debugging purposes, so that you can
+ * g_print() the path or dump it in a gdb session.
+ *
+ * Returns: A new string describing @path.
+ **/
+char *
+gtk_widget_path_to_string (const GtkWidgetPath *path)
+{
+  GString *string;
+  guint i, j;
+
+  g_return_val_if_fail (path != NULL, NULL);
+
+  string = g_string_new ("");
+
+  for (i = 0; i < path->elems->len; i++)
+    {
+      GtkPathElement *elem;
+
+      elem = &g_array_index (path->elems, GtkPathElement, i);
+
+      if (i > 0)
+        g_string_append_c (string, ' ');
+
+      g_string_append (string, g_type_name (elem->type));
+
+      if (elem->name)
+        {
+          g_string_append_c (string, '(');
+          g_string_append (string, g_quark_to_string (elem->name));
+          g_string_append_c (string, ')');
+        }
+
+      if (elem->classes)
+        {
+          for (j = 0; j < elem->classes->len; j++)
+            {
+              g_string_append_c (string, '.');
+              g_string_append (string, g_quark_to_string (g_array_index (elem->classes, GQuark, j)));
+            }
+        }
+
+      if (elem->regions)
+        {
+          GHashTableIter iter;
+          gpointer key, value;
+
+          g_hash_table_iter_init (&iter, elem->regions);
+          while (g_hash_table_iter_next (&iter, &key, &value))
+            {
+              GtkRegionFlags flags = GPOINTER_TO_UINT (value);
+              static const char *flag_names[] = {
+                "even",
+                "odd",
+                "first",
+                "last",
+                "sorted"
+              };
+
+              g_string_append_c (string, ' ');
+              g_string_append (string, g_quark_to_string (GPOINTER_TO_UINT (key)));
+              for (j = 0; j < G_N_ELEMENTS(flag_names); j++)
+                {
+                  if (flags & (1 << j))
+                    {
+                      g_string_append_c (string, ':');
+                      g_string_append (string, flag_names[j]);
+                    }
+                }
+            }
+        }
+    }
+
+  return g_string_free (string, FALSE);
+}
+
 /**
  * gtk_widget_path_prepend_type:
  * @path: a #GtkWidgetPath
index 2c9c981e41cd2eaec08ca93a08823cb6cd057572..a84c420548bb2ea79b46fc9ce0bad07ec93a7cad 100644 (file)
@@ -39,6 +39,7 @@ GtkWidgetPath * gtk_widget_path_new                 (void);
 GtkWidgetPath * gtk_widget_path_copy                (const GtkWidgetPath *path);
 void            gtk_widget_path_free                (GtkWidgetPath       *path);
 
+char *          gtk_widget_path_to_string           (const GtkWidgetPath *path);
 gint            gtk_widget_path_length              (const GtkWidgetPath *path);
 
 gint            gtk_widget_path_append_type         (GtkWidgetPath       *path,